﻿using PARK.Common.Const;
using SqlSugar;
using System;
using Yitter.IdGenerator;

namespace PARK.Attend.Entitys
{
    /// <summary>
    /// 考勤设备
    /// </summary>
    [SugarTable("attend_machs")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class AttendMachsEntity
    {
        /// <summary>
        ///考勤机Id
        /// </summary>
        [SugarColumn(ColumnName = "machlId", IsPrimaryKey = true)]
        public string machlId { get; set; }        
        /// <summary>
        /// 考勤机名称
        /// </summary>
        [SugarColumn(ColumnName = "machName")]        
        public string machName { get; set; }        
        /// <summary>
        /// 考勤机SN
        /// </summary>
        [SugarColumn(ColumnName = "machSN")]        
        public string machSN { get; set; }        
        /// <summary>
        /// 所在区域
        /// </summary>
        [SugarColumn(ColumnName = "doorAreaId")]        
        public string DoorAreaId { get; set; }        
        /// <summary>
        /// 所在区域名称
        /// </summary>
        [SugarColumn(ColumnName = "doorAreaName")]        
        public string DoorAreaName { get; set; }        
        /// <summary>
        /// 所在位置
        /// </summary>
        [SugarColumn(ColumnName = "ctlposition")]        
        public string Ctlposition { get; set; }
        
        /// <summary>
        /// 物联卡号
        /// </summary>
        [SugarColumn(ColumnName = "IOTcardNo")]        
        public string IoTcardNo { get; set; }
        
        /// <summary>
        /// 到期截止日
        /// </summary>
        [SugarColumn(ColumnName = "IOTcardvalidity")]        
        public DateTime? IoTcardvalidity { get; set; }
        
        /// <summary>
        /// 启用
        /// </summary>
        [SugarColumn(ColumnName = "EnabledMark")]        
        public int? EnabledMark { get; set; }
        
        /// <summary>
        /// 说明
        /// </summary>
        [SugarColumn(ColumnName = "Description")]        
        public string Description { get; set; }
        
        /// <summary>
        /// 创建用户
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserId")]        
        public string CreatorUserId { get; set; }
        
        /// <summary>
        /// 创建用户姓名
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserName")]        
        public string CreatorUserName { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnName = "CreatorTime")]        
        public DateTime? CreatorTime { get; set; }
        
        /// <summary>
        /// 修改用户
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyUserId")]        
        public string LastModifyUserId { get; set; }
        
        /// <summary>
        /// 修改用户姓名
        /// </summary>
        [SugarColumn(ColumnName = "F_LastModifyUserName")]        
        public string LastModifyUserName { get; set; }
        
        /// <summary>
        /// 修改时间
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyTime")]        
        public DateTime? LastModifyTime { get; set; }
        
        /// <summary>
        /// 删除标记 1是 0否
        /// </summary>
        [SugarColumn(ColumnName = "IsDeleted")]        
        public int? IsDeleted { get; set; }
        
        /// <summary>
        /// 删除用户
        /// </summary>
        [SugarColumn(ColumnName = "DeleteUserId")]        
        public string DeleteUserId { get; set; }
        
        /// <summary>
        /// 删除用户姓名
        /// </summary>
        [SugarColumn(ColumnName = "DeleteUserName")]        
        public string DeleteUserName { get; set; }
        
        /// <summary>
        /// 删除时间
        /// </summary>
        [SugarColumn(ColumnName = "DeleteTime")]        
        public DateTime? DeleteTime { get; set; }      
        
        /// <summary>
        /// 是否在线 1是 0否
        /// </summary>
        [SugarColumn(ColumnName = "IsOnline")]        
        public int? IsOnline { get; set; }
        
        /// <summary>
        /// 最后在线时间
        /// </summary>
        [SugarColumn(ColumnName = "LastOnLineTime")]        
        public DateTime? LastOnLineTime { get; set; }
        
        /// <summary>
        /// 同步时钟 0否 1已同步
        /// </summary>
        [SugarColumn(ColumnName = "IsSyntime")]        
        public int? IsSyntime { get; set; }        
        /// <summary>
        /// 最后同步时钟时间
        /// </summary>
        [SugarColumn(ColumnName = "LastSyntime")]
        public DateTime? LastSyntime { get; set; }        
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "dbDate")]        
        public DateTime? DbDate { get; set; }

        /// <summary>
        /// 所属公司Id
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }

        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.machlId = YitIdHelper.NextId().ToString();
            this.CreatorTime = DateTime.Now;
            this.IsDeleted = 0;
            this.DbDate = DateTime.Now;
            this.IsOnline = 0;
            this.IsSyntime = 0;
            this.EnabledMark = 1;
            if (!string.IsNullOrEmpty(userId))
            {
                this.CreatorUserId = CreatorUserId == null ? userId : CreatorUserId;
                this.CreatorUserName = CreatorUserName == null ? userName : CreatorUserName;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        public virtual void LastModify(string Id)
        {
            this.machlId = Id;
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.LastModifyTime = DateTime.Now;
            if (!string.IsNullOrEmpty(userId))
            {
                this.LastModifyUserId = userId;
                this.LastModifyUserName = userName;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        public virtual void Delete()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.DeleteTime = DateTime.Now;
            this.IsDeleted = 1;
            if (!string.IsNullOrEmpty(userId))
            {
                this.DeleteUserId = userId;
                this.DeleteUserName = userName;
            }
        }
    }
}